<?php
// +----------------------------------------------------------------------
//            -------------------------
//           /   / ----------------\  \
//          /   /             \  \
//         /   /              /  /
//        /   /    /-------------- /  /
//       /   /    /-------------------\  \
//      /   /                   \  \
//     /   /                     \  \
//    /   /                      /  /
//   /   /      /----------------------- /  /
//  /-----/      /---------------------------/
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://baimifan.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 汪利东,2016-04-15 13:42
// +----------------------------------------------------------------------

namespace Admin\Controller;


class CardTypeController extends BaseController
{
    public function index()
    {
        $Cardtype=M("Deposit_type");
        $data=$Cardtype->order("month")->select();
        $this->assign("data",$data);
        $this->display();
    }

    public function export(){
        $Cardtype=M("Deposit_type");
        $data=$Cardtype->order("month")->select();
        $file = excel_export($data);
        ouput_Browser($file);
        
    }

    function del(){
        $type_id=I("get.type_id");
        $Cardtype=M("Deposit_type");
        $Cardtype->where("type_id=$type_id")->delete();
        $this->success("删除成功");
    }

    function edit(){
        $type_id=I("get.type_id");
        if($type_id==""){
            $this->display();
            return;
        }
        $Cardtype=M("Deposit_type");
        $data=$Cardtype->where("type_id=$type_id")->find();
        $this->assign("data",$data);
        $this->display();
    }
    function doEdit(){
        $type_id=I("get.type_id");
        $data['name']=I("post.name");
        $data['month']=I("post.month");
        $data['price']=I("post.price");
        $data['num_delivery']=I("post.num_delivery");
        $data['num_activity']=I("post.num_activity");
        $data['discount_apply']=I("post.discount_apply");
        $data['discount_buy']=I("post.discount_buy");
        $data['wx_show']=I("post.wx_show")=='on'?'1':'0';
        $Cardtype=M("Deposit_type");
        if($type_id==""){
            $type_id=0;
        }
        $count=$Cardtype->where("type_id=$type_id")->count();
        if($count>0){
            $Cardtype->where("type_id=$type_id")->data($data)->save();
            $this->success("修改成功",U("index"));
        }else{
            $Cardtype->data($data)->add();
            $this->success("添加成功",U("index"));
        }
    }
}